package com.ruoyi.project.product.lineManage.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.product.lineManage.domain.LineManage;
import com.ruoyi.project.product.lineManage.mapper.LineManageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LineManageServiceImpl implements LineManageService {
    //声明mapper层属性
    @Autowired
    private LineManageMapper lineManageMapper;
    @Override
    public List<LineManage> selectLineManageList(LineManage lineManage) {
        return lineManageMapper.selectLineManageListMapper(lineManage);
    }

    /**
     * 校验类型名称
     * @param lineManage
     * @return
     */
    @Override
    public String checkTypeNameUnique(LineManage lineManage) {
        Long typeId = StringUtils.isNull(lineManage.getTypeId()) ? -1L : lineManage.getTypeId();
        LineManage info = lineManageMapper.checkTypeNameUnique(lineManage.getTypeName());
        if (StringUtils.isNotNull(info) && info.getTypeId().longValue() != typeId.longValue())
        {
            return UserConstants.TYPE_NAME_NOT_UNIQUE1;
        }
        return UserConstants.TYPE_NAME_UNIQUE1;
    }

    /**
     * 新增产品系列
     * @param lineManage
     * @return
     */
    @Override
    public int insertLineManage(LineManage lineManage) {
        return lineManageMapper.insertLineManage(lineManage);
    }

    /**
     * 获取要修改的产品系列信息
     * @param typeId
     * @return
     */
    @Override
    public LineManage selectTypeById(Long typeId) {
        return lineManageMapper.selectLineManageByIdMapper(typeId);
    }

    /**
     * 保存产品系列修改
     * @param lineManage
     * @return
     */
    @Override
    public int updateLineManage(LineManage lineManage) {
        return lineManageMapper.updateLineManageMapper(lineManage);
    }

    /**
     * 删除产品系列
     * @param ids
     * @return
     */
    @Override
    public int deleteLineManageByIds(String ids) {
        Long[] lineManageIds = Convert.toLongArray(ids);
        return lineManageMapper.deleteLineManageByIds(lineManageIds);
    }
}
